package com.sqlsession.database;

import com.sqlsession.DataBase;
import com.sqlsession.DateSource;
import com.sqlsession.dm8.DmSqlDateSource;
import com.sqlsession.filter.DbFilter;
import com.sqlsession.mysql.MySqlDateSource;

public enum DbType {
    MYSQL {
        @Override
        public DateSource getDateSource(String host, String port, String user, String password, String name, DbFilter filter, String desc) {
            return new MySqlDateSource(getDataBase(host, port, user, password, name, filter, desc));
        }
    }, DM {
        @Override
        public DateSource getDateSource(String host, String port, String user, String password, String name, DbFilter filter, String desc) {
            return new DmSqlDateSource(getDataBase(host, port, user, password, name, filter, desc));
        }

        @Override
        public String formatName(String name) {
            return String.format("\\\"%s\\\"", super.formatName(name));
        }
    };

    DataBase getDataBase(String host, String port, String user, String password, String name, DbFilter filter, String desc) {
        return new DataBase(this, port, host, user, password, name, filter, desc);
    }

    public abstract DateSource getDateSource(String host, String port, String user, String password, String name, DbFilter filter, String desc);


    public String formatName(String name) {
        return name;
    }
}
